package com.iis.gui;

import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BorderFactory;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import javax.swing.JLabel;
import javax.swing.JButton;

import com.iis.entity.Admin;

public class LoginForm extends JFrame {

	private JPanel contentPane;
	private JTextField uidTF;
	private JTextField passTF;
	private static LoginForm frame;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					frame = new LoginForm();
					frame.setVisible(true);
					frame.setTitle("Login - Insurance Information System [IIS]");
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public LoginForm() {
		getContentPane().setLayout(null);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 400, 300);
		contentPane = new JPanel();
		contentPane.setLayout(null);
		
		JPanel loginPanel = new JPanel();
		loginPanel.setLayout(null);
		loginPanel.setBounds(30, 30, 320, 180);
		loginPanel.setBorder(BorderFactory.createTitledBorder("Login Area"));
		
		
		JLabel lblUID = new JLabel("  Username");
		lblUID.setFont(lblUID.getFont().deriveFont(12.0f));
		lblUID.setBounds(10, 30, 100, 30);
		JLabel lblPass = new JLabel("  Password");
		lblPass.setFont(lblPass.getFont().deriveFont(12.0f));
		lblPass.setBounds(10, 70, 100, 30);
		
		uidTF = new JTextField();
		uidTF.setColumns(20);
		uidTF.setFont(uidTF.getFont().deriveFont(14.0f));
		uidTF.setBounds(110, 30, 190, 30);
		
		passTF = new JPasswordField();
		passTF.setColumns(20);
		passTF.setFont(passTF.getFont().deriveFont(16.0f));
		passTF.setBounds(110, 70, 190, 30);
		
		loginPanel.add(lblUID);
		loginPanel.add(uidTF);
		
		loginPanel.add(lblPass);
		loginPanel.add(passTF);
		
		JButton btnLogin = new JButton("LOGIN");
		btnLogin.setBounds(200, 120, 100, 40);
		loginPanel.add(btnLogin);
		
		contentPane.add(loginPanel);
		setContentPane(contentPane);
		
		btnLogin.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				// TODO Auto-generated method stub
				if(uidTF.getText().equals(Admin.administrator.username) && passTF.getText().equals(Admin.administrator.password)){
					new MainWindow(frame);
					frame.setVisible(false);
				}
				else{
					JOptionPane.showMessageDialog(frame,"Username : admin\nPassword : admin","LOGIN CREDENTIALS",JOptionPane.INFORMATION_MESSAGE);
				}
				uidTF.setText("");
				passTF.setText("");
			}
		});
	}
}
